home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7003 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: pacbell.com!well!usenet
  2. From: rickyarm@well.com ()
  3. Newsgroups: comp.lang.c
  4. Subject: I need some help re: scanf, getchar
  5. Date: Sat, 17 Feb 1996 03:14:08 GMT
  6. Organization: The Whole Earth 'Lectronic Link, Sausalito, CA
  7. Message-ID: <4g3h6g$9ri@nkosi.well.com>
  8. NNTP-Posting-Host: sr-tty5-ppp.well.com
  9. X-Newsreader: Forte Free Agent v0.71
  10.  
  11. Hello there,
  12.  
  13. My name is Rick Armanino and I am having some trouble with my program
  14. for a class that I am taking.  Can someone help with these problems??
  15.  
  16. 1.  the first time through the do/while loop runs smooth; user enters
  17. 1 for entering new accounts finishes then the loop displays the menu
  18. again but getchar() does not wait for the users input on the second
  19. time around and goes straight to the default of the switch.  WHY AND
  20. WHERE IS GETCHAR GETING ITS INPUT FROM?
  21.  
  22. 2.  Inside the first choice of entering new accounts the user is
  23. prompt if there are more accounts to be entered.  Inorder to make the
  24. do/while loop function I had to read something into a garbage varible.
  25. WHY IS THIS HAPPENING??
  26.  
  27. THANKS FOR ANY ADVICE---rickyarm@well.com
  28. ------------------------------------------------------------------------------------------------
  29.  
  30. do{   /*menu part of the program prompts user to choose one of 5
  31. options  responce is placed into 'ch' */
  32.  
  33. printf("\tEnter Selection: ");
  34.    ch = getchar();  /*WHERE IS GETCHAR() GETTING ITS INPUT FROM ON THE
  35. SECOND TIME AROUND IN THE LOOP*/
  36.    printf("the value of 'ch' is: ");
  37.    putchar(ch);
  38. printf("\n");
  39.  
  40. switch(ch) {
  41.     case '1':/*begining of entering a new account*/
  42.         do {
  43.     bufnode = GetUserInput();
  44.  
  45.         if (!root)
  46.         root = InsertSort(root, root, bufnode);
  47.     else
  48.                    InsertSort(root, root, bufnode);
  49.  
  50.     printf("\n\t\tAre there more accounts to be entered?\n");
  51. scanf("%c", &garbage);
  52.     scanf("%c", &ans); /*THERE IS SOMETHING STILL IN THE BUFFER? BECAUSE
  53. THE ONLY WAY THAT THIS WHILE LOOP CONTINUES IS IF SOMETHING IS READ
  54. INTO GARBAGE  ANY SUGGESTTIONS WOULD BE OF GREAT HELP*/
  55.  
  56.     }while(ans == 'y');
  57.  
  58.        
  59.     if (root)
  60.         Print_Inorder(root);
  61.     break; /*end of entering new account option*/
  62.  
  63.     case '2': /*Search for an account option*/
  64.             printf("Name of the account you want to search for: \n");
  65.         scanf("%s", keylastname);
  66.  
  67.             temp = root;
  68.         temp = Search(root, keylastname); 
  69.  
  70.                 if (temp != NULL)
  71.                    printf("the acount that you found is: %s\n", temp->lastname);
  72.         else
  73.                     printf("No account was found by that name\n");
  74.         break; /*end of search option*/
  75.  
  76.     case '3': /*make a deposit*/
  77.  
  78.     case '4': /*make a withdrawal*/
  79.  
  80.     default: /*exit the system*/
  81.         endsys = 1;
  82.                 printf("the end of the system\n");
  83.         break;
  84.     }/*end of swich statement*/
  85. }while (!endsys);
  86. }
  87.  
  88.